package com.example.wy.androidhomework4;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

public class xuancanActivity extends AppCompatActivity {
    private static final String TAG = "xuancanActivity";

    EditText mEtUsername;
    SeekBar mSbSeek;
    TextView mTvNumber;
    TextView mTvPinzhong;
    Button btn_ok;
    CheckBox cb_la,cb_su,cb_hun,cb_suan;
    ImageView iv_tp;
    int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xuancan );

        mEtUsername = (EditText) findViewById(R.id.et_username);
        Intent intent = getIntent();
        String name = intent.getStringExtra("admin");
        mEtUsername.setText(name);

        mTvNumber=findViewById(R.id.tv_number);
        mTvPinzhong=findViewById(R.id.tv_pinzhong);
        iv_tp=findViewById(R.id.iv_tp);
        mSbSeek = (SeekBar) findViewById(R.id.sb_seek);
        btn_ok = (Button) findViewById(R.id.btn_ok);
        cb_la= (CheckBox) findViewById(R.id.cb_la);
        cb_hun= (CheckBox) findViewById(R.id.cb_hun);
        cb_su= (CheckBox) findViewById(R.id.cb_su);
        cb_suan= (CheckBox) findViewById(R.id.cb_suan);
        mSbSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
               mTvNumber.setText(Integer.toString(progress) + "元");


                id= Integer.parseInt(String.valueOf(progress));

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Log.e("------------", "onStartTrackingTouch: 开始拖动");
                Log.e(TAG, "onStartTrackingTouch: " );
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Log.e("------------", "onStopTrackingTouch: 停止滑动");
            }
        });
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean la=cb_la.isChecked();
                boolean  su= cb_su.isChecked();
                boolean  hun=cb_hun.isChecked();
                boolean  suan=cb_suan.isChecked();
                TextView viewById = (TextView) findViewById(R.id.tv_number);
                String pric= viewById.getText().toString();
                mTvPinzhong =(TextView) findViewById(R.id.tv_pinzhong);
                iv_tp= (ImageView) findViewById(R.id.iv_tp);

//
                Log.e(TAG, "onClick: " );

                if((suan && la && su)){
                    if( id<=15){
                        //桂林米粉
                      mTvPinzhong.setText("桂林米粉");

                        iv_tp.setImageResource(R.mipmap.guilin);
                    }
                }else {

                }
                if((la && hun)){
                    if( id<=80){
                        //麻辣火锅
                      mTvPinzhong.setText("麻辣火锅");
                       iv_tp.setImageResource(R.mipmap.malahuoguo);
                    }
                }
                if(suan &&hun){
                    if(id<=35){
                        //酸菜牛肉面
                       mTvPinzhong.setText("酸菜牛肉面");
                       iv_tp.setImageResource(R.mipmap.suncainiuroumian);
                    }
                }
                if(su){
                    if(id<=38){
                        //西芹炒百合
                       mTvPinzhong.setText("西芹炒百合");
                       iv_tp.setImageResource(R.mipmap.xiqin);
                    }
                }
                if(hun){
                    if (id<=60){
                        //红烧肉
                      mTvPinzhong.setText("红烧肉");
                       iv_tp.setImageResource(R.mipmap.hongshaorou);
                    }
                }

            }
        });

    }



}
